OpenFalcon CentOS 7.2部署

简介

OpenFalcon是一款企业级、高可用、可扩展的开源监控解决方案。

环境准备

当前平台相关组件部署在OAM主机,其余主机均部署agent.

redis

1
yum install -y redis

mysql

安装MySQL

1
yum install -y mysql-server

初始化MySQL表结构

1
2
3
4
5
6
7
8
cd /tmp/ && git clone https://github.com/open-falcon/falcon-plus.git
cd /tmp/falcon-plus/scripts/mysql/db_schema/
mysql -h 127.0.0.1 -u root -pYmQwODk2Y2I0ZmVm < 1_uic-db-schema.sql
mysql -h 127.0.0.1 -u root -pYmQwODk2Y2I0ZmVm < 2_portal-db-schema.sql
mysql -h 127.0.0.1 -u root -pYmQwODk2Y2I0ZmVm < 3_dashboard-db-schema.sql
mysql -h 127.0.0.1 -u root -pYmQwODk2Y2I0ZmVm < 4_graph-db-schema.sql
mysql -h 127.0.0.1 -u root -pYmQwODk2Y2I0ZmVm < 5_alarms-db-schema.sql
rm -rf /tmp/falcon-plus/

注意,请确保redis和MySQL已启动。

后端

创建工作目录

1
2
3
4
export FALCON_HOME=/usr/local
export WORKSPACE=$FALCON_HOME/open-falcon
mkdir -p $WORKSPAC
tar -xzvf open-falcon-v0.2.0.tar.gz -C $WORKSPACE

修改配置文件

修改所有组件的MySQL信息root:password

启动

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
cd $WORKSPACE
./open-falcon start

# 检查所有模块的启动状况
./open-falcon check


# ./open-falcon [start|stop|restart|check|monitor|reload] module
./open-falcon start agent

./open-falcon check
falcon-graph UP 53007
falcon-hbs UP 53014
falcon-judge UP 53020
falcon-transfer UP 53026
falcon-nodata UP 53032
falcon-aggregator UP 53038
falcon-agent UP 53044
falcon-gateway UP 53050
falcon-api UP 53056
falcon-alarm UP 53063

For debugging , You can check $WorkDir/$moduleName/log/logs/xxx.log

Agent

简介

agent用于采集机器负载监控指标,比如cpu.idle、load.1min、disk.io.util等等,每隔60秒push给Transfer。agent与Transfer建立了长连接,数据发送速度比较快,agent提供了一个http接口/v1/push用于接收用户手工push的一些数据,然后通过长连接迅速转发给Transfer。

部署说明

agent需要部署到所有要被监控的机器上,比如公司有10万台机器,那就要部署10万个agent。agent本身资源消耗很少,不用担心。

配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
{
"debug": true, # 控制一些debug信息的输出,生产环境通常设置为false
"hostname": "", # agent采集了数据发给transfer,endpoint就设置为了hostname,默认通过`hostname`获取,如果配置中配置了hostname,就用配置中的
"ip": "", # agent与hbs心跳的时候会把自己的ip地址发给hbs,agent会自动探测本机ip,如果不想让agent自动探测,可以手工修改该配置
"plugin": {
"enabled": false, # 默认不开启插件机制
"dir": "./plugin", # 把放置插件脚本的git repo clone到这个目录
"git": "https://github.com/open-falcon/plugin.git", # 放置插件脚本的git repo地址
"logs": "./logs" # 插件执行的log,如果插件执行有问题,可以去这个目录看log
},
"heartbeat": {
"enabled": true, # 此处enabled要设置为true
"addr": "127.0.0.1:6030", # hbs的地址,端口是hbs的rpc端口
"interval": 60, # 心跳周期,单位是秒
"timeout": 1000 # 连接hbs的超时时间,单位是毫秒
},
"transfer": {
"enabled": true,
"addrs": [
"127.0.0.1:18433"
], # transfer的地址,端口是transfer的rpc端口, 可以支持写多个transfer的地址,agent会保证HA
"interval": 60, # 采集周期,单位是秒,即agent一分钟采集一次数据发给transfer
"timeout": 1000 # 连接transfer的超时时间,单位是毫秒
},
"http": {
"enabled": true, # 是否要监听http端口
"listen": ":1988",
"backdoor": false
},
"collector": {
"ifacePrefix": ["eth", "em"], # 默认配置只会采集网卡名称前缀是eth、em的网卡流量,配置为空就会采集所有的,lo的也会采集。可以从/proc/net/dev看到各个网卡的流量信息
"mountPoint": []
},
"default_tags": {
},
"ignore": { # 默认采集了200多个metric,可以通过ignore设置为不采集
"cpu.busy": true,
"df.bytes.free": true,
"df.bytes.total": true,
"df.bytes.used": true,
"df.bytes.used.percent": true,
"df.inodes.total": true,
"df.inodes.free": true,
"df.inodes.used": true,
"df.inodes.used.percent": true,
"mem.memtotal": true,
"mem.memused": true,
"mem.memused.percent": true,
"mem.memfree": true,
"mem.swaptotal": true,
"mem.swapused": true,
"mem.swapfree": true
}
}

进程管理

1
2
3
4
./open-falcon start agent  启动进程
./open-falcon stop agent 停止进程
./open-falcon monitor agent 查看日志
./falcon-agent --check 健康检查,或者浏览器访问其1988端口

前端

克隆前端组件代码

1
2
cd $WORKSPACE
git clone https://github.com/open-falcon/dashboard.git

安装依赖包

1
2
3
4
5
6
7
8
9
10
11
yum install -y python-virtualenv
yum install -y python-devel
yum install -y openldap-devel
yum install -y mysql-devel
yum groupinstall "Development tools"


cd $WORKSPACE/dashboard/
virtualenv ./env

./env/bin/pip install -r pip_requirements.txt -i https://pypi.douban.com/simple

修改配置

1
2
3
4
5
6
7
dashboard的配置文件为: 'rrd/config.py',请根据实际情况修改

## API_ADDR 表示后端api组件的地址
API_ADDR = "http://127.0.0.1:8080/api/v1"

## 根据实际情况,修改PORTAL_DB_*, 默认用户名为root,默认密码为""
## 根据实际情况,修改ALARM_DB_*, 默认用户名为root,默认密码为""

启动

开发者模式启动

1
2
3
./env/bin/python wsgi.py

open http://127.0.0.1:8081 in your browser.

生产环境启动

1
2
3
bash control start

open http://127.0.0.1:8081 in your browser.

停止dashboard运行

1
bash control stop

查看日志

1
bash control tail

dashbord用户管理

dashbord没有默认创建任何账号包括管理账号,需要你通过页面进行注册账号。
想拥有管理全局的超级管理员账号,需要手动注册用户名为root的账号(第一个帐号名称为root的用户会被自动设置为超级管理员)。
超级管理员可以给普通用户分配权限管理。

小提示:注册账号能够被任何打开dashboard页面的人注册,所以当给相关的人注册完账号后,需要去关闭注册账号功能。只需要去修改api组件的配置文件cfg.json,将signup_disable配置项修改为true,重启api即可。当需要给人开账号的时候,再将配置选项改回去,用完再关掉即可。

初次使用

注册管理员账号

访问dashboard主机8081端口,点击”sign up”

用户名必须为root

个人信息维护

注意填写邮箱地址和IM信息,IM部分可以写微信号,这些信息为以后的报警通知使用。

Dashboard 使用介绍

  • 左边的侧边栏会显示所有加入的agent主机,或者自定义的endpoint。
  • 右中间位置limit50表示显示50行内容,可以自行选择。
  • 右下方是endpiont的监控项目,选中后点击看图即可画图。

画图示例

1、选中监控项,点击选择看图视角

2、这样图就出来啦

另外还可以自定义screen,此处不再具体介绍

hostgroup

简单说就是主机组,然后绑定模板
hostgroup-》Add host

template

Like this.

监控使用

参考 http://book.open-falcon.org/zh_0_2/usage/getting-started.html

报警组件

报警部分分为邮件和微信报警,其中微信报警。启动邮件报警部分有点特殊,因为阿里云机器默认是不允许开发25端口的,因此只能使用ssl的456端口。但是问题又来了,官方的组件不支持ssl。因此对于这个问题只能是重新编译。

邮件

https://github.com/GitHamburg/mail-provider.git

1.二进制安装(推荐)

下载编译好的二进制

1
2
3
4
wget http://cactifans.hi-www.com/open-falcon/mail-provider.tar.gz
mkdir -p mail-provider
tar zxvf mail-provider.tar.gz -C mail-provider
cd mail-provider

修改cfg.json文件相关信息,使用

1
./control start

2.源码编译(如无科学上网方法,请勿尝试)

下载之后为源码,安装golang环境,环境配置参考golang环境配置 编译方法

1
2
3
4
5
6
7
cd $GOPATH/src
mkdir github.com/open-falcon/ -p
cd github.com/open-falcon/
git clone https://github.com/GitHamburg/mail-provider.git
cd mail-provider
go get ./...
./control build

编译成功之后,修改cfg.json文件相关信息,使用

1
./control start

3、使用方法

坐着说可以发送给多人,但是实际curl使用的时候发现并不可以。

1
curl http://$ip:4000/sender/mail -d "tos=a@a.com&subject=xx&content=yy"

微信

https://github.com/Yanjunhui/chat.git

一.申请企业号

以个人邮箱申请就可以, 不通过企业认证的话,有200人的限制,一般足够用了

二.获取对接权限

1、获取corpid

登录后,我的企业 —-> 企业信息 –> CorpID

将 CorpID 配置到配置文件 config.conf 内 的 CorpID

2、开启回调模式获取key

登录后,顶部菜单[企业应用] —-> 添加应用
进入新添加的应用
拿到 AgentId 和 Secret

3、关注微信公众号

使用微信关注企业号才可以从微信收到信息,否则只能从微信企业号 APP 中收到信息

三、使用

1
git clone https://www.github.com/yanjunhui/chat.git

修改chat配置文件


1
2
3
4
5
6
7
8
9
10
11
12
13
#http 服务端口
[http]
port = 4567

#微信接口信息
[weixin]
CorpID = xxxxxx
#ID 应用ID
AgentId = 1
# Secret
Secret = xxxxxxx
#最后一个无所谓
EncodingAESKey = wodH5dMSQtlfySHED5dkk6dF7saukFpPxlwhWRsVeEn

1
2
3
4
5
打开目录 cd chat
启动 ./control.sh start
停止 ./control.sh stop
重启 ./control.sh restart
状态 ./control.sh status

但是更新了版本,不知道为啥不正常,发布了微信。

推荐另一种方式,更好调试。

Falcon-wechat

1
2
3
4
mkdir -p /usr/local/falcon-wechat
cd /usr/local/falcon-wechat
wget https://dl.cactifans.com/open-falcon/falcon-wechat-0.0.1.tar.gz
tar zxvf falcon-wechat-0.0.1.tar.gz
1
2
3
4
5
6
7
8
9
10
11
12
{
"debug": true,
"http": {
"listen": "0.0.0.0:9527",
"token": ""
},
"wechat": {
"corpid": "wxa7c63522727b6bf0",
"secret": "d5S-_XGVd-5HA0o9bkvMMK5Wh1qwCC-YQei4WcL9hSM",
"agentid": 1
}
}

然后修改alarm接口,重启即可,还能看日志。

https://www.cactifans.org/open-falcon/1788.html

相关资料

http://book.open-falcon.org/zh_0_2/
https://github.com/open-falcon/falcon-plus

------ 本文结束 ------

版权声明

Medivh's Notes by Medivh is licensed under a Creative Commons BY-NC-ND 4.0 International License.
Medivh创作并维护的Medivh's Notes博客采用创作共用保留署名-非商业-禁止演绎4.0国际许可证
本文首发于Medivh 博客( http://www.mknight.cn ),版权所有,侵权必究。